#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100010;
typedef long long ll;
int a[N];
ll cnt;
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	
	cnt = a[1];
	for (int i = 1; i < n; i++)
	{
		if (a[i] < a[i + 1])
			cnt += a[i + 1] - a[i];
	}
	cout << cnt << endl;
	return 0;
}